function WebAppController(){
	
	this.view = {
		extend: "base",
		put: {content: "modules/service-header.html"},
		adhocControllers: ["entry-list", "subscriptions"]
	};
	
	this.handler = function(){
		
		var user = request.getAttr("user"), htmlForm, customizeForm = {},unsubscribeForm = {},
		customize = (request.params.customize == ""),
		unsubscribe = (request.params.unsubscribe == ""),
		serviceObj = db.services.getSingle({guid: request.uri.tokens.service}),
		service = serviceObj && serviceObj.value;
			
			
		if(customize && service){
			htmlForm = new HTMLForm.generator(request);
			customizeForm = htmlForm.create({
				id: "customizeForm",
				method: "post",
				inputs: [
					{"name": {label: "name:", value: request.params.name || service.name ,validate: {required: true, minlength: 2}}},
					{"description": {label: "description:", value: request.params.description || service.description, type: "textarea", validate: {minlength: 2}}},
					{"owner": {label: "subject:", value: request.params.owner || service.owner, validate: {minlength: 2}}},
					{"type": {label: "entry type:", value: request.params.type || service.type, validate: {minlength: 2}}},
					{"submit_": {type: "submits", choices: ["apply", "cancel"]}}
				]
			});
		}
		
		if(unsubscribe && service){
			htmlForm = new HTMLForm.generator(request);
			unsubscribeForm = htmlForm.create({
				id: "unsubscribeForm",
				method: "post",
				inputs: [
					{"submit_": {type: "submits", choices: ["yes", "no"]}}
				]
			});
		}
		
		this.get = function(showErrors){
			
			request.setAttr("services", [serviceObj]);
			if(serviceObj){
				var service = serviceObj.value;
				$("#service-header").append("<img src=/static/i/rss-feed-icon-32.png class=icon alt='' border=0 />" +
					"<h2 class=service-name>" + service.name + "</h2>" +
					"<p class=service-desc>" + service.description + "</p><ul>" +
					((user && (service.creator === user.username)) ? "<li class=" + ((unsubscribe) ? "active" : "") + "><a href='?unsubscribe'>unsubscribe</a></li>" +
							"<li class=" + ((customize) ? "active" : "") + "><a href='?customize'>customize</a></li>"
						: "<li><a href='?subscribe'>subscribe</a></li>") +	"</ul>");
				
				if(customize && customizeForm){
					$("#service-header").after("<div class=tab-panel><h3>Customize service</h3>" + customizeForm.html(showErrors) + "</div>");
					$.each(customizeForm.data, function(k, v){
						$("#customizeForm_"+k).attr("value", service[k]);
					});
					
				}
				
				if(unsubscribe && unsubscribeForm){
					$("#service-header").after("<div class=tab-panel><h3>Are you sure you want to unsubscribe from this service?</h3>" + unsubscribeForm.html(showErrors) + "</div>");
										
				}
				
			}
		}
		
		this.post = function(){
			var canceled = false;
			
			if(customizeForm.values && (customizeForm.values.submit_ === "cancel")){
				response.redirect(request.uri.tokens.service);
				canceled = true;
			}
			if(!canceled && customizeForm.pass){
				alert(customizeForm.values.type)
				service.name = customizeForm.values.name;
				service.description = customizeForm.values.description;
				service.owner = customizeForm.values.owner;
				service.type = customizeForm.values.type || "entry";
				db.services.update(service, {guid: service.guid});
			}
			
			if(unsubscribeForm.pass){
				if(unsubscribeForm.values.submit_ === "yes"){
					
				}
				response.redirect(request.uri.tokens.service);
			}
			this.get(!customizeForm.pass);
		}
		
	}

}